package sibots;

import java.rmi.RemoteException;

import robocode.HitRobotEvent;
import robocode.HitWallEvent;
import robocode.rescue.ConstantesExecucao;
import robocode.rescue.RoboInfo;
import jason.RoboJason;
import jason.ambiente.HZTeamEnv;
import jason.ambiente.TORTATeamEnv;


public class TortaFuzzy extends RoboJason {

	private FuzzyAtaque fa;
	private FuzzyDefesa fd;
	private String estrategia;
	public TortaFuzzy(){
		fa = new FuzzyAtaque(this);
		fd = new FuzzyDefesa(this);
		estrategia = "";
	}
	@Override
	public void mainLoop() {
		
		if ( info.getAcao() != null){
			if(info.getAcao().equals(HZTeamEnv.actionAtk)){
				estrategia = "Ataque";
			    fa.main();
			}
			else if (info.getAcao().equals(TORTATeamEnv.actionBlqRobo1)) {
				fd.setRoboBloqueado(TORTATeamEnv.actionBlqRobo1);
				fd.main();
			}
			else if (info.getAcao().equals(TORTATeamEnv.actionBlqRobo2)) {
				fd.setRoboBloqueado(TORTATeamEnv.actionBlqRobo2);
				fd.main();
			}
			else if (info.getAcao().equals(TORTATeamEnv.actionBlqRobo3)) {
				fd.setRoboBloqueado(TORTATeamEnv.actionBlqRobo3);
				fd.main();
			}
			else if (info.getAcao().equals(TORTATeamEnv.actionBlqRobo4)) {
				fd.setRoboBloqueado(TORTATeamEnv.actionBlqRobo4);
				fd.main();
			}
			
		}
		else{
			doNothing();
		}
	}
	@Override
    public void onHitRobot(HitRobotEvent event){
    	if(estrategia.equals("Ataque")){
    		fa.trataBatida(event.getBearing());
    	}else{
    		double angulo = event.getBearing();
        	if (angulo > -90 && angulo <= 90){
                setBack(10);
            } else {
                setAhead(10);
            }
        	
        	execute();
    	}
    }
    @Override
    public void onHitWall(HitWallEvent event){
    }
	@Override
	public void setup() {
		// TODO Auto-generated method stub
		
	}


}